#! /bin/bash


function help(){
	echo -e "\
 lspt prints the coordinates of a node with a given index. \n\
 Indices are assumed to start at 0.\n\
\n\
 usage : $0 [meshname] [index] [-h -H]\n\
         o meshname: basename of the mesh, or the corresponding pts file\n\
         o index   : index of a node, can also be a list of indices.\n\
         -H        : Include index of the nodes
         -h        : Suppress index of the nodes"
}

INCLUDE_INDEX="true"
for i in $@; do
        case $i in
        -h) INCLUDE_INDEX="false";;
        -H) INCLUDE_INDEX="true";;
        -?) help; exit;;
        *) ;;
        esac
done

if [ $# -le 1 ]; then
	help;
	exit;
fi

if [ -f $1 ]; then
	PTSFILE=$1
else
	if [ -f $1.pts ]; then
		PTSFILE=$1.pts
	else
		help
		echo " error : Mesh with name $1 not found!";
		exit -1;
	fi
fi

shift 1

while [ $# -gt 0 ]; do
	# ignore all options
	if [ "${1:0:1}" == "-" ]; then shift 1; continue; fi	

	if ! [ $1 -eq $1 2> /dev/null ]; then
		help;
		echo " error : $1 isn't a number"
		exit -1;
	fi 
	
	LINE=`nl -s": " -bt -v\-1 ${PTSFILE} | grep "^[ ]*$1:"`

	if [ "$INCLUDE_INDEX" == "true" ]; then
		
		echo "--"$LINE;
	else
		echo $LINE | cut -d " " -f 2,3,4;
	fi;
	
	shift 1
done;
	
